package main

func maximumSubarray(nums []int) int {
	if len(nums) == 0 {
		return 0
	}
	maxV := nums[0]
	maxToCurrent := nums[0]
	for i := 1; i < len(nums); i++ {
		maxToCurrent = max(nums[i]+maxToCurrent, nums[i])
		maxV = max(maxV, maxToCurrent)
	}
	return maxV
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
